package com.putable.nmc.world;

import java.util.EnumMap;
import java.util.EnumSet;
import java.util.InputMismatchException;


import junit.framework.TestCase;

public class TestCustomerDistribution extends TestCase {

    public static void main( String[] args) {
        junit.textui.TestRunner.run(TestCustomerDistribution.class);
    }

    private CustomerDistribution d0;
    
    protected void setUp() throws Exception {
        super.setUp();
        d0 = new CustomerDistribution();
        d0.timeStarts = 100;
        d0.timeEnds = 250;
        d0.sumArrivalTimes = 0;
        d0.arrivalDistribution =
            new EnumMap<CustomerType,Double>(CustomerType.class);
        double num = 5;
        for (CustomerType c : EnumSet.allOf(CustomerType.class)) {
            d0.arrivalDistribution.put(c,num);
            d0.sumArrivalTimes += num;
            num += 5;
        }
    }

    public void testToString() {
        assertEquals("100.0 250.0 5.0 10.0 15.0 20.0",d0.toString());
    }
    
    public void testFromString() {
        String sd = d0.toString();
        CustomerDistribution cd = CustomerDistribution.fromString(sd);
        String sd2 = cd.toString();
        assertTrue(d0 != cd);
        assertEquals(sd,sd2);
    }
    
    public void testFromString2() {
        {
            String sd = d0.toString();
            boolean caught = false;
            try {
                CustomerDistribution cd = CustomerDistribution.fromString(sd);
                assertNotNull(cd);
            }
            catch (InputMismatchException e) { caught = true; }
            assertFalse(caught);
        }
    }
}
